package store.lunangangster.bpmn.converter.parser;

import javax.xml.stream.XMLStreamReader;
import org.apache.commons.lang3.StringUtils;
import store.lunangangster.bpmn.constant.BpmnXmlConstant;
import store.lunangangster.bpmn.model.BpmnModel;

/**
 * 用于definitions标签的解析
 *
 * @author cwk
 * @version 1.0
 */
public class DefinitionsParser implements BpmnXmlConstant {

  public void parse(XMLStreamReader xsr, BpmnModel bpmnModel) {
    bpmnModel.setDefaultNamespace(xsr.getNamespaceURI());
    bpmnModel.setTargetNamespace(xsr.getAttributeValue(null, ATTRIBUTE_TARGET_NAMESPACE));
    for (int i = 0; i < xsr.getNamespaceCount(); i++) {
      String prefix = xsr.getNamespacePrefix(i);
      if (StringUtils.isNotBlank(prefix)) {
        bpmnModel.addNamespace(prefix, xsr.getNamespaceURI(prefix));
      }
    }
  }
}
